package com.aaa.outbound.service.impl;


import com.aaa.entity.outbound.Pick;
import com.aaa.outbound.mapper.PickMapper;
import com.aaa.outbound.service.PickService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wjf
 * @since 2020-11-26
 */
@Service
public class PickServiceImpl extends ServiceImpl<PickMapper, Pick> implements PickService {
    @Autowired
    private PickMapper pickMapper;

    @Override
    public Page<Pick> searchPick(Integer page, Integer limit, Pick pick) {
        Page<Pick> pageinfo=new Page<>(page,limit);
        String pickno=pick.getPickno();
        String picktaskno=pick.getPicktaskno();
        String state=pick.getState();
        QueryWrapper<Pick> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(pickno)){
            queryWrapper.like("pickno",pickno);
        }
        if(StringUtils.isNotEmpty(picktaskno)){
            queryWrapper.like("picktaskno",picktaskno);
        }
        if(StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        this.pickMapper.selectPage(pageinfo,queryWrapper);
        return pageinfo;
    }

    @Override
    public Integer addPick(Pick pick) {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        pick.setId(null);
        pick.setPickno("PN"+dateFormat.format(now));
        return pickMapper.insert(pick);
    }
}
